// subPages/communityService/homemakingDetails/homemakingDetails.js
const app = getApp();
var utils = require("../../../utils/util");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    themeColor:app.globalData.themeColor,
    shopDetails:'',
    bannerList:[],
    bannerSet:{
        interval:1000,
        duration:500,
        autoplay:false,
        circular:true,
        indicatorDots:true,
        indicatorColor:'rgba(0,0,0,.4)',
        indicatorActiveColor: app.globalData.themeColor,
        current:0
    },
    bannerStyle:{
      width:'100%',
      height:'300rpx'
    }
  },
  checkImg(e){
      let index = e.currentTarget.dataset.index;
      let that = this;
      let bannerList = that.data.shopDetails.head_banner;
      // console.log(index);
      let urls = [];
      for(let i in bannerList){
        urls.push(bannerList[i].banner_img)
      }
      wx.previewImage({
          current: urls[index],
          urls: urls // 需要预览的图片http链接列表
      })
  },
    makeCall:function(){
      let that = this;
      wx.makePhoneCall({
          phoneNumber:that.data.shopDetails.phone
      })
    },
    toComment(e){
      var businessId = e.currentTarget.dataset.businessid;
        wx.navigateTo({
            url:`/subPages/communityService/comment/comment?businessId=${businessId}&type=0`
        })
    },
    toMap(){
        var _this = this;
        wx.openLocation({
            latitude:Number(_this.data.shopDetails.lat),
            longitude:Number(_this.data.shopDetails.lng),
            scale:14,
            name:_this.data.shopDetails.shop_name,
            address:_this.data.shopDetails.address
        })
    },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      let that = this;
      utils.setNavBarTitle('商家详情');
      that.setData({
          shopId:options.id
      })
      // console.log(options);
      that.getHomemakingDetails();
  },
    getHomemakingDetails(){
      let that = this;
      utils.getAjax(`${app.globalData.apiUrl}/get_community_service_home_shop_content`,function(res){
          console.log(res);
          that.setData({
              shopDetails:res.data
          })
      },{
          id:that.data.shopId
      })
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
